package jfprincesstests;

import java.util.Arrays;

import jfprincesstests.agents.TestAgents;
import jfprincesstests.finiteautomata.TestFinitAuthomata;
import jfprincesstests.goaltests.TestDeviceChoose;
import jfprincesstests.graphsupport.TestGraphGenerate;
import jfprincesstests.structures.*;
import jfprincesstests.structures.negotiation.*;
import jfprincesstests.systemtests.*;
import jfprincesstests.utilityfuncprotocol.TestUtilityFuncBasedNegotiationProtocol;
import jfprincesstests.elenaofsavoia.TestHillClimbingSolver;
import junit.framework.Test;
import junit.framework.TestSuite;
import junit.textui.ResultPrinter;
import laboratoryQ.junit.ignore.patch.BaseTestCase;
import laboratoryQ.junit.ignore.patch.IgnorableResultPrinter;
import laboratoryQ.junit.ignore.patch.IgnorableTestRunner;

public class AllTests extends BaseTestCase {
	private static void addGoalTests(TestSuite suite) {
		suite.addTestSuite(TestDeviceChoose.class);
	}

	private static void addUnitTests(TestSuite suite) {
		suite.addTestSuite(AllTests.class);
		suite.addTestSuite(TestCommands.class);
		suite.addTestSuite(TestConstruction.class);
		suite.addTestSuite(TestIfConstruction.class);
		suite.addTestSuite(TestConditionsConstruction.class);
		suite.addTestSuite(TestNegotiationServices.class);
		suite.addTestSuite(TestInvestmentCompNegotiation.class);
		suite.addTestSuite(TestAgents.class);
		suite.addTestSuite(TestNegotiation.class);
		suite.addTestSuite(TestPremiumAssignment.class);
		suite.addTestSuite(TestVariables.class);
		suite.addTestSuite(TestForConstruction.class);
		suite.addTestSuite(TestNegotiationUtils.class);
		suite.addTestSuite(TestPremiumWithUtilityFunctionProtocol.class);
		suite.addTestSuite(TestUtilityFuncBasedNegotiationProtocol.class);
		suite.addTestSuite(TestNegotiationProtocolSystem.class);
		suite.addTestSuite(TestFinitAuthomata.class);
		suite.addTestSuite(TestGraphGenerate.class);

		suite.addTestSuite(TestHillClimbingSolver.class);
	}

	public static Test suite() {
		TestSuite suite = new TestSuite("Tests for JFuzzyPrincepless");

		addGoalTests(suite);
		addUnitTests(suite);

		return suite;
	}

	public static void main(String[] args) {
		ResultPrinter rp = new IgnorableResultPrinter(System.out);
		IgnorableTestRunner tr = new IgnorableTestRunner(rp);

		tr.doRun(suite(), !waitCanceled(args));

		int exitCode = tr.wasSummarySuccessful() ? 0 : 1;
		System.exit(exitCode);
	}

	public void testCheckAssertionsEnabled() {
		boolean caught = false;
		try {
			assert Math.sin(1) > 2.0 : "sin(Re) < =1.0";
			throw new RuntimeException();
		} catch (AssertionError e) {
			caught = true;
		}
		assertTrue(caught);
	}

	private static boolean waitCanceled(String[] args) {
		return Arrays.asList(args).contains("nowait");
	}
}
